// 封装文章接口
import axios from '@/utils/request'
/**
 * 文章列表
 * @param {*} channelId 频道id
 * @param {*} timestamp 时间戳
 * @returns
 */
export const getArticleList = (channelId, timestamp) =>
  axios({
    url: '/v1_0/articles',
    params: {
      channel_id: channelId,
      timestamp
    }
  })

/**
 * 不感兴趣文章
 * @param {*} target  文章id
 * @returns
 */
export const aritcleDeslike = (target) =>
  axios({
    method: 'POST',
    url: '/v1_0/article/dislikes',
    data: {
      target
    }
  })

/**
 * 举报文章
 * @param {*} target 文章id
 * @param {*} type 举报类型
 * @returns
 */
export const articleReports = (target, type) =>
  axios({
    method: 'POST',
    url: '/v1_0/article/reports',
    data: {
      target,
      type
    }
  })

/**
 * 获取文章详情
 * @param {*} artId 文章id
 * @returns
 */
export const getArticleDetail = (artId) =>
  axios({
    url: '/v1_0/articles/' + artId
  })

/**
 * 关注文章用户
 * @param {*} target 关注用户的id
 * @returns
 */
export const followUser = (target) =>
  axios({
    url: '/v1_0/user/followings',
    method: 'POST',
    data: {
      target
    }
  })

/**
 * 取消关注文章用户
 * @param {*} target 取消关注用户的id
 * @returns
 */
export const unfollowUser = (target) =>
  axios({
    url: '/v1_0/user/followings/' + target,
    method: 'DELETE'
  })

/**
 * 取消点赞
 * @param {*} target 文章的id
 * @returns
 */
export const deleteLike = (target) =>
  axios({
    url: '/v1_0/article/likings/' + target,
    method: 'DELETE'
  })

/**
 * 点赞
 * @param {*} target 文章id
 * @returns
 */
export const addLike = (target) =>
  axios({
    url: '/v1_0/article/likings',
    method: 'POST',
    data: {
      target
    }
  })

/**
 * 取消不喜欢
 * @param {*} target 文章id
 * @returns
 */
export const deleteDislike = (target) =>
  axios({
    url: '/v1_0/article/dislikes/' + target,
    method: 'DELETE'
  })

/**
 * 加不喜欢
 * @param {*} target 文章id
 * @returns
 */
export const addDislike = (target) =>
  axios({
    url: '/v1_0/article/dislikes',
    method: 'POST',
    data: {
      target
    }
  })

/**
 * 获取文章评论
 * @param {*} source 文章id
 * @param {*} offset 获取评论数据的偏移量，值为评论id，表示从此id的数据向后取，不传表示从第一页开始读取数据
 * @returns
 */
export const getArticleComment = (source, offset) =>
  axios({
    url: '/v1_0/comments',
    params: {
      type: 'a',
      source,
      offset,
      limit: 10
    }
  })

/**
 * 添加评论
 * @param {*} target 文章id
 * @param {*} content 评论内容
 * @returns
 */
export const addArticleComment = (target, content) =>
  axios({
    method: 'POST',
    url: '/v1_0/comments',
    data: {
      target,
      content
    }
  })

/**
 * 评论点赞
 * @param {*} target 评论id
 * @returns
 */
export const likeComment = (target) =>
  axios({
    method: 'POST',
    url: '/v1_0/comment/likings',
    data: {
      target
    }
  })

/**
 * 取消评论点赞
 * @param {*} target 评论id
 * @returns
 */
export const dislikeComment = (target) =>
  axios({
    method: 'DELETE',
    url: '/v1_0/comment/likings/' + target
  })

/**
 * 获取回复文章评论的评论
 * @param {*} source 评论id
 * @param {*} offset 获取评论数据的偏移量，值为评论id，表示从此id的数据向后取，不传表示从第一页开始读取数据
 * @returns
 */
export const getComment = (source, offset) =>
  axios({
    url: '/v1_0/comments',
    params: {
      type: 'c',
      source,
      offset,
      limit: 10
    }
  })

/**
 * 对评论添加回复评论
 * @param {*} target 评论id
 * @param {*} content 评论内容
 * @param {*} artId 文章id
 * @returns
 */
export const addComment = (target, content, artId) =>
  axios({
    method: 'POST',
    url: '/v1_0/comments',
    data: {
      target,
      content,
      art_id: artId
    }
  })
